
Simulator=function(input,output){
  var self=this;

  self.addTasks=function(){
    self.taskQueue=input.getTasks();
    //Log(self.taskQueue);
    return self;
  }
  self.simulate=function(scheduler){
    self.addTasks();
    //wiping screen before drawing
    output.clear();
    if(scheduler==undefined){
      alert('Not implemented :(');
      return self;
    }
    //adding initial task states to scheduler
    scheduler.addTasks(self.taskQueue);

    //drawing the board

    scheduler.tick();
    //drawing the init of all the tasks
    var sts=scheduler.getTaskStates();
    for(var i=0;i<sts.length;i++){
      output.drawTrack(sts[i]).drawInit(sts[i]);
      //output.drawInit(sts[i]);
    }

    //simulation algorithm
    var n=0;
    Log('------------- time='+n++);
    while(!scheduler.finished()){
      sts=scheduler.getTaskStates();
      //drawing task states 
      for(var i=0;i<sts.length;i++){
        output.drawTaskState(sts[i]);
        //Log('Total: '+sts[i].getTimeTotal());
        //Log('Quantum: '+sts[i].quantum);
      }
      //Log('--tick--');
      scheduler.tick();
      Log('------------- time='+n++);
    }
    for(var i=0;i<sts.length;i++){
      self.taskQueue[i].summary=Array(
        sts[i].totalTime,
        sts[i].execTimeTotal,
        sts[i].execTimeRunning,
        sts[i].RIP
      );
    }

  }
}

simulator=new Simulator(input,output);

